#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

#define get RUBB

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;
using db = double;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;

int a[N],b[N],get[N],n,m;
ll ans;
bool vis[N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in,m = in; for(int i = 1;i <= n;i++) a[i] = in; for(int i = 1;i <= m;i++) b[i] = in;
	get[0] = get[1] = inf; get[a[1]] = 0; for(int i = 1;i <= n;i++) get[a[i]] = min(get[a[i]],min(i - 1,n - i + 1));
	for(int i = 1;i <= m;i++) vis[b[i]] = true; if(vis[0] && get[0] == inf) return puts("-1"),0; if(vis[1] && get[1] == inf) return puts("-1"),0;
	int cur = 1; while(b[cur] == a[1] && cur <= m) cur++,ans++;
	if(cur <= m) {
		ans += get[b[cur]] + 1;
		int lst = b[cur]; cur++;
		for(int i = cur;i <= m;i++) {
			ans += (b[i] != lst) + 1;
			lst = b[i];
		}
	}
	printf("%lld\n",ans); return 0;
}
